# -*-coding:utf-8-*-
import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from GraphicView import GraphicView
from JS_widgets.Draw_Tab import DrawTab

class DrawWindow(QWidget):
    def __init__(self):
        super(DrawWindow, self).__init__()
        #全局变量
        self.time_list=['凌晨','黎明','拂晓','清晨','早晨','上午','中午','下午','黄昏','傍晚','晚上','半夜','深夜']
        self.weather_list=['晴','阴天','炎热','闷热','虹','雾','凉','霜','雨','露','雪','雹','雷','冰','闪电','冰柱']
        self.drawing=-1
        self.draw_type='curve'  # 绘制的类型 rect矩形  curve曲线  line直线
        self.select_btn_style="color : #FF8C00"
        self.current_attr={}  #当前笔刷属性
        self.current_deep='0'  #当前深度.gitignore

        self.IMG_PATH=os.path.join(os.path.dirname(__file__),'imgs')
        self.setWindowTitle('江山笔')
        self.icon = QIcon()
        self.icon_path = os.path.join(self.IMG_PATH,'s.png')
        self.icon.addPixmap(QPixmap(self.icon_path))
        self.setWindowIcon(self.icon)

        self.main_layout=QVBoxLayout()
        self.hS=QSplitter(Qt.Horizontal)
        self.graph=GraphicView()
        self.hS.addWidget(self.graph)
        self.setting_frame=QFrame()
        self.setting_layout=QVBoxLayout()
        self.control_layout=QHBoxLayout()
        self.draw_btn=QPushButton('绘图')
        self.draw_btn.setStyleSheet(self.select_btn_style)
        self.draw_btn.clicked.connect(self._open_drawplane)
        self.move_btn=QPushButton('移动')
        self.move_btn.clicked.connect(self._set_move)
        self.view_btn=QPushButton('视图')
        self.view_btn.clicked.connect(self._open_viewplane)
        self.env_btn=QPushButton('环境')
        self.env_btn.clicked.connect(self._open_envplane)
        self.control_layout.addWidget(self.draw_btn)
        self.control_layout.addWidget(self.move_btn)
        self.control_layout.addWidget(self.view_btn)
        self.control_layout.addWidget(self.env_btn)

        #绘图
        self.draw_frame=QFrame()
        self.draw_frame_layout=QVBoxLayout()
        self.draw_table=DrawTab()
        self.draw_table.choose_attr_Signal.connect(self.set_current_attr)
        self.draw_frame_layout.addWidget(self.draw_table)
        self.draw_frame.setLayout(self.draw_frame_layout)
        self.draw_frame.setVisible(True)

        # 视图frame
        self.view_frame=QFrame()
        self.view_frame_layout=QVBoxLayout()
        self.view_frame_layout.setAlignment(Qt.AlignTop)
        self.view_frame_layout.setSpacing(25)
        self.view_frame_layout.setContentsMargins(20,40,20,20)
        self.view_height_layout=QHBoxLayout()
        self.view_label=QLabel('      视图高度:')
        self.view_eidt=QLineEdit()
        self.view_height_layout.addWidget(self.view_label)
        self.view_height_layout.addWidget(self.view_eidt)
        self.view_center_layout=QHBoxLayout()
        self.view_center_label=QLabel('到中心点的距离:')
        self.view_center_edit=QLineEdit()
        self.view_center_edit.textChanged.connect(self._current_deep_change)
        self.view_center_layout.addWidget(self.view_center_label)
        self.view_center_layout.addWidget(self.view_center_edit)
        self.view_frame_layout.addLayout(self.view_height_layout)
        self.view_frame_layout.addLayout(self.view_center_layout)
        self.view_frame.setLayout(self.view_frame_layout)
        self.view_frame.setVisible(False)
        #环境frame
        self.env_frame=QFrame()
        self.env_layout=QVBoxLayout()
        self.env_layout.setAlignment(Qt.AlignTop)
        self.time_layout=QHBoxLayout()
        self.time_label=QLabel('时间段:')
        self.time_comb=QComboBox()
        self.time_comb.addItems(self.time_list)
        self.time_layout.addWidget(self.time_label)
        self.time_layout.addWidget(self.time_comb)
        self.weather_layout = QHBoxLayout()
        self.weather_label=QLabel('天 气:')
        self.weather_comb=QComboBox()
        self.weather_comb.addItems(self.weather_list)
        self.weather_layout.addWidget(self.weather_label)
        self.weather_layout.addWidget(self.weather_comb)

        self.env_layout.addLayout(self.time_layout)
        self.env_layout.addLayout(self.weather_layout)
        self.env_frame.setLayout(self.env_layout)
        self.env_frame.setVisible(False)

        self.setting_layout.addLayout(self.control_layout)
        self.setting_layout.addWidget(self.draw_frame)
        self.setting_layout.addWidget(self.view_frame)
        self.setting_layout.addWidget(self.env_frame)
        self.setting_frame.setLayout(self.setting_layout)
        self.hS.addWidget(self.setting_frame)
        self.main_layout.addWidget(self.hS)
        self.setLayout(self.main_layout)

        self.choose_widgets=[self.draw_frame,self.view_frame,self.env_frame]



    def show_widget(self,num):
        for i in range(len(self.choose_widgets)):
            if i==num:
                self.choose_widgets[i].setVisible(True)
            else:
                self.choose_widgets[i].setVisible(False)

    def _open_drawplane(self):
        self.show_widget(0)
    def _open_viewplane(self):
        self.show_widget(1)
    def _open_envplane(self):
        self.show_widget(2)

    def _set_move(self):
        self.drawing*=-1
        if self.drawing==1:  #当可以移动时
            self.move_btn.setStyleSheet('color : #00FF00')
        else:
            self.move_btn.setStyleSheet('color : #000000')

    def set_current_attr(self,attr):
        self.current_attr=attr
        print("current_attr:", self.current_attr)

    def _current_deep_change(self,text):
        self.current_deep=text

    # def keyPressEvent(self, QKeyEvent):
    #     print('按下键了')
    #     if QKeyEvent.Key()==Qt.Key_Space:
    #         print('开始切换')
    #         # self._set_move()
    #         print('空格切换')
    #     super(DrawWindow, self).keyPressEvent(QKeyEvent)




if __name__ == '__main__':
    app=QApplication(sys.argv)
    d=DrawWindow()
    d.show()
    sys.exit(app.exec_())


